package com.cyh.nio;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

//通过之间数据传输（transferFrom）
public class FileChannelDemo03 {
    public static void main(String[] args) throws IOException {
        //创建两个fileChannel

        RandomAccessFile aFile = new RandomAccessFile("D:\\cyh\\work_java\\TestNioOrIo\\src\\com\\cyh\\2.txt", "rw");
        FileChannel fromChannel = aFile.getChannel();

        RandomAccessFile bFile = new RandomAccessFile("D:\\cyh\\work_java\\TestNioOrIo\\src\\com\\cyh\\3.txt", "rw");
        FileChannel toChannel = bFile.getChannel();

        //fromChannel 传输到 toChannel
        toChannel.transferFrom(fromChannel, 0, fromChannel.size());

        aFile.close();
        bFile.close();

    }
}
